package com.corpgovernment.common.base;

import com.ctrip.corp.obt.generic.exception.ResponseStatus;

/**
 * @author zl.cui
 * @date 2023/3/2
 */
public enum ResponseCodeEnum implements ResponseStatus {

    /**
     * Success
     */
    SUCCESS(20000, "Success"),

    SYSTEM_EXCEPTION(1101, "System Exception"),


    /**
     * Retry
     */
    RETRY_AFTER(20010, "Retry"),

    /**
     * Degrade
     */
    SERVICE_DEGRADE(20101, "Degrade"),

    /**
     * DB Error
     **/
    DB_FAILUE(30100, "DB Error"),

    /**
     * Redis Error
     */
    REDIS_FAILURE(30010, "Redis Error"),

    /**
     * Apollo Error
     */
    APOLLO_FAILURE(30020, "Apollo Error"),

    /**
     * Qmq Error
     */
    ROCKETMQ_FAILURE(30030, "Qmq Error"),
    /**
     * Qmq retry Error
     */
    ROCKETMQ_RETRY(30031, "Qmq Retry Error"),

    /**
     * Null Request
     */
    NULL_REQUEST(40000, "Null Request"),

    /**
     * Invalid Request
     */
    BAD_REQUEST(40001, "Invalid Request"),

    /**
     * Invalid Response
     */
    BAD_RESPONSE(40002, "Invalid Response"),

    /**
     * Null Response
     */
    NULL_RESPONSE(40003, "Null Response"),

    /**
     * Duplicate Request
     */
    DUPLICATED_REQUEST(40010, "Duplicate Request"),

    /**
     * Processing Request
     */
    IN_PROCESSING_REQUEST(40011, "Processing Request"),

    /**
     * Invalid OrderId
     */
    INVALID_ORDERID(40020, "Invalid OrderId"),

    /**
     * Invalid ProductOrderId
     */
    INVALID_PRODUCT_ORDERID(40021, "Invalid ProductOrderId"),

    /**
     * Invalid ProductId
     */
    INVALID_PRODUCT_ID(40022, "Invalid ProductId"),

    /**
     * Not Corporation Order
     */
    ORDER_DETAIL_NOT_CORP_ORDER(50001, "Not Corporation Order"),

    /**
     * App ID Unauthorized
     */
    ORDER_DETAIL_APP_ID_UNAUTHORIZED(50002, "App ID Unauthorized"),

    /**
     * OrderId List Size Exceeds
     */
    ORDER_DETAIL_ORDER_ID_LIST_EXCEEDS(50003, "OrderId List Size Exceeds"),

    /**
     * Serve Internal Error
     */
    SERVER_ERROR(99999, "Serve Internal Error"),

    /**
     * NA
     */
    NA(999999999, "NA");

    private int code;
    private String desc;

    private ResponseCodeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }



    public static ResponseCodeEnum valueOf(int intValue, ResponseCodeEnum defaultValue) {
        ResponseCodeEnum[] responseCodeArray = ResponseCodeEnum.values();
        for (ResponseCodeEnum responseCode : responseCodeArray) {
            if (intValue == responseCode.code()) {
                return responseCode;
            }
        }
        return defaultValue;
    }

    @Override
    public String toString() {
        return String.valueOf(code);
    }


    @Override
    public int code() {
        return code;
    }

    @Override
    public String message() {
        return desc;
    }
}
